// pages/page/page.js
var httpUtil = require('../../utils/httpUtil.js');
var util = require('../../utils/util.js');
var app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    bannerList: [],
    goodsTravelList: [],
    hotList:[],
    columnList:[],
    page:0
  }, 


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({
      page:0
    })
    //轮播图
    that.getBanner();
    that.getGoodsTraveHot();
    that.getGoodsHot(that.data.page);
    var userInfo = util.getKey("userInfo");

    if (userInfo == false || userInfo == '') {
      app.onLaunch();
    }
  },
  //获取轮播图
  getBanner: function() {
    var that = this;
    httpUtil.getHttp("/banner/get", {}, function(res) {
      that.setData({
        bannerList: res
      })
    })
    httpUtil.getHttp("/banner/get/column", {}, function (res) {
      that.setData({
        columnList: res
      })
    })
  },
  //获取热门出行
  getGoodsTraveHot: function() {
    var that = this;

    httpUtil.getHttp("/goods_travel/hot", {}, function(res) {
      that.setData({
        goodsTravelList: res
      })
    })
  },
  //获取装备热门出行
  getGoodsHot: function (page) {
    var that = this;

    httpUtil.getHttp("/goods_travel/hot?type=4&page=" + page, {}, function (res) {
      var hotList=that.data.hotList;
      for(var i=0;i<res.length;i++){
        that.data.hotList.push(res[i]);
      }
      
      that.setData({
        hotList: hotList
      })
    })
  },
  
  //获取装备热门出行
  nextGoods: function (page) {
    var that = this;
   var page = that.data.page+1;
    that.getGoodsHot(page);
      that.setData({
        page: page
      })
  
  }, 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.showNavigationBarLoading();
    //模拟加载
    setTimeout(function() {
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, 1500);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  linkMore: function(e) {
    var id = e.target.dataset.id;
    if(id!=undefined&&id!=''){

    wx.navigateTo({
      url: '../detail/detail?id=' + id
    })

    }
  },
  goTicket: function() {
    wx.navigateTo({
      url: '../ticket/ticket'
    })
  },
  goTravel: function() {
    wx.navigateTo({
      url: '../heel/heel'
    })
  },
  goCustom: function() {
    wx.navigateTo({
      url: '../custom/custom'
    })
  },
  getGoods:function(e){

    var that=this;
    var id = e.target.dataset.id;
    console.log(id);
    switch(id){
      case 1: 
        that.goVisa()
      break;
      case 2:
        that.gobaoCar()
        break;
      case 3:
        that.goTicket()
        break;
      case 4:
        that.goCustom()
        break;
      case 5:
        that.goTravel()
        break;
    }
  },
  goVisa: function() {
    wx.navigateTo({
      url: '../selVisa/selVisa'
    })
  },
  gobaoCar: function() {
    wx.navigateTo({
      url: '../category_chartere/category_chartere'
    })
  },
  moreOpre: function(res) {
    console.log(res)
    wx.switchTab({
      url: '../classify/classify'
    })
  },
  gotoTravel: function(res) {

    wx.navigateTo({
      url: '../travel/travel'
    })
  },
  necessity: function(res) {

    wx.navigateTo({
      url: '../necessity/necessity'
    })
  },
  linkList: function(e) {
    var goodsType = e.target.dataset.type;
    if (goodsType == undefined) {
      return;
    }
    wx.navigateTo({
      url: '../travel/travel?type=' + goodsType
    })
  },
  travelUrl: function(e) {
    var id = e.target.dataset.id;
    var goodsType = e.target.dataset.type;
      console.log(id);
    console.log(goodsType);

     if (id == undefined) {
      return;
    } if (goodsType == undefined) {
      return;
    }
    if (goodsType != undefined && goodsType == 0) {
      wx.navigateTo({
        url: '../visaInfo/visaInfo?id=' + id
      })
      return
    }
    if (goodsType != undefined && goodsType == 4) {
      wx.navigateTo({
        url: '../detail/detail?id=' + id
      })
      return
    }
    if (goodsType != undefined && goodsType == 0) {
      wx.navigateTo({
        url: '../visaInfo/visaInfo?id=' + id
      })
      return
    }
    wx: wx.navigateTo({
      url: '../proInfo/proInfo?id=' + id,
    })
  }, search:function(e){
    wx.navigateTo({
      url: '../search/search'
    })
  }
})